home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / cmap.cxx next >
Encoding:
C/C++ Source or Header  |  1999-05-14  |  4.8 KB  |  153 lines

  1. //
  2. // "$Id: cmap.cxx,v 1.4.2.1 1999/05/14 09:07:08 bill Exp $"
  3. //
  4. // Colormap generation program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // This program produces the contents of "fl_cmap.h" as stdout
  27.  
  28. // #include <gl/gl.h>
  29. #include <stdio.h>
  30.  
  31. // This table is initialized with color values I got by reading the
  32. // colormap on an IRIX 4.3 machine:
  33.  
  34. // "full intensity colors" have been turned down some to make white
  35. // background less intense by default.  The hope is that this will make
  36. // fltk programs more friendly on color-adjusted screens.  If you want
  37. // pure colors you should get them out of the colormap.
  38.  
  39. //#define III 244 // maximum intensity of the basic colors
  40.  
  41. // that results in errors and unshared colormap entries, so full intensity:
  42. #define III 255 // maximum intensity of the basic colors
  43.  
  44. static short cmap[256][3] = {
  45. // 3-bit colormap:
  46.   {  0,  0,  0},    // black
  47.   {III,  0,  0},    // red
  48.   {  0,III,  0},    // green
  49.   {III,III,  0},    // yellow
  50.   {  0,  0,III},    // blue
  51.   {III,  0,III},    // magenta
  52.   {  0,III,III},    // cyan
  53.   {III,III,III},    // white
  54. // pastel versions of those colors:
  55.   { 85, 85, 85},    // 1/3 gray
  56.   {198,113,113},    // salmon? pale red?
  57.   {113,198,113},    // pale green
  58.   {142,142, 56},    // khaki
  59.   {113,113,198},    // pale blue
  60.   {142, 56,142},    // purple, orchid, pale magenta
  61.   { 56,142,142},    // cadet blue, aquamarine, pale cyan
  62.   {170,170,170},    // 2/3 gray
  63. // These next 16 are the FL_FREE_COLOR area.  For compatability with
  64. // some existing DD programs, I prefill them with the random colors
  65. // you get on a 5.3 machine:
  66.   { 16, 16, 16},
  67.   {128, 40,128},
  68.   {198, 30, 30},
  69.   { 66, 30, 30},
  70.   {176,140,140},
  71.   {  0, 20, 20},
  72.   { 20, 10, 10},
  73.   { 40, 20, 20},
  74.   { 60, 30, 30},
  75.   {  0, 80, 80},
  76.   {  0, 40, 40},
  77.   { 20, 20,  0},
  78.   { 40, 40,  0},
  79.   { 80, 80, 10},
  80.   {150,150, 20},
  81.   {160, 10, 10},
  82. // The rest of the colormap is a gray ramp and table, filled in below:
  83. };
  84.  
  85. // This is Fl::background from Fl_get_system_colors.C, with modifications:
  86.  
  87. #define FL_GRAY_RAMP 32
  88. #define FL_NUM_GRAY  24
  89. #define FL_GRAY 49 // old value is 47
  90. typedef unsigned char uchar;
  91. #include <math.h>
  92.  
  93. void background(uchar r, uchar g, uchar b) {
  94.   // replace the gray ramp so that color 47 (by default 2/3) is this color
  95.   if (!r) r = 1; else if (r==255) r = 254;
  96.   double powr = log(r/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
  97.   if (!g) g = 1; else if (g==255) g = 254;
  98.   double powg = log(g/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
  99.   if (!b) b = 1; else if (b==255) b = 254;
  100.   double powb = log(b/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
  101.   for (int i = 0; i < FL_NUM_GRAY; i++) {
  102.     double gray = i/(FL_NUM_GRAY-1.0);
  103.     cmap[i+FL_GRAY_RAMP][0] = uchar(pow(gray,powr)*255+.5);
  104.     cmap[i+FL_GRAY_RAMP][1] = uchar(pow(gray,powg)*255+.5);
  105.     cmap[i+FL_GRAY_RAMP][2] = uchar(pow(gray,powb)*255+.5);
  106.   }
  107. }
  108.  
  109. int main() {
  110.   int i,r,g,b;
  111. #if 0
  112.   /* Read colormap colors into internal table */
  113.   long cmwin;
  114.   noport();
  115.   cmwin = winopen("CM");
  116.   for (i=0; i<256; i++)
  117.     getmcolor(i,&cmap[i][0],&cmap[i][1],&cmap[i][2]);
  118.   winclose(cmwin);
  119. #endif
  120. // overwrite the X allocation area with one color so people are
  121. // discouraged from using it:
  122.   for (i=16; i<32; i++) {cmap[i][0]=cmap[i][1]=cmap[i][2] = 85;}
  123.  
  124.   // fill in the gray ramp:
  125.   background(0xc0, 0xc0, 0xc0); // microsoft colors
  126.   // background(cmap[15][0],cmap[15][1],cmap[15][2]); // old fltk colors
  127.   // copy the 1/3 and 2/3 gray to the closest locations in gray ramp:
  128.   cmap[39][0] = cmap[39][1] = cmap[39][2] = cmap[8][0];
  129.   cmap[47][0] = cmap[47][1] = cmap[47][2] = cmap[15][0];
  130.  
  131.   // fill in the color cube
  132.   i = 56;
  133.   for (b=0; b<5; b++)
  134.     for (r=0; r<5; r++)
  135.       for (g=0; g<8; g++) {
  136.     cmap[i][0] = r*255/4;
  137.     cmap[i][1] = g*255/7;
  138.     cmap[i][2] = b*255/4;
  139.     i++;
  140.       }
  141.  
  142.   for (i=0; i<256; i++) {
  143.     printf("\t0x%02x%02x%02x00",cmap[i][0],cmap[i][1],cmap[i][2]);
  144.     if (i < 255) printf(",\n");
  145.   }
  146.   printf("\n");
  147.   return 0;
  148. }
  149.  
  150. //
  151. // End of "$Id: cmap.cxx,v 1.4.2.1 1999/05/14 09:07:08 bill Exp $".
  152. //
  153.